<PageHeader as |p|>
  <p.top>
    {{key-value-header
      baseKey=baseKey
      path="vault.cluster.access.leases.list"
      model=clusterController.model.name
      root=backendCrumb
      showCurrent=true
    }}
  </p.top>
  <p.levelLeft>
    <h1 class="title is-3">
      {{#link-to "vault.cluster.access.leases.list-root"}}
        Leases
      {{/link-to}}
    </h1>
  </p.levelLeft>
</PageHeader>

<Toolbar>
  <ToolbarFilters>
    {{navigate-input
       filterFocusDidChange=(action "setFilterFocus")
       filterDidChange=(action "setFilter")
       filter=filter
       filterMatchesKey=filterMatchesKey
       firstPartialMatch=firstPartialMatch
       baseKey=(get baseKey "id")
       shouldNavigateTree=true
       mode='leases'
       placeholder='Filter leases'
     }}
     {{#if filterFocused}}
       &nbsp;
       &nbsp;
       {{#if filterMatchesKey}}
         {{#unless filterIsFolder}}
           <p class="help has-text-grey is-size-8">
             <kbd>ENTER</kbd> to go to see details
           </p>
         {{/unless}}
       {{/if}}
       {{#if firstPartialMatch}}
         <p class="help has-text-grey is-size-8">
           <kbd>TAB</kbd> to complete
         </p>
       {{/if}}
     {{/if}}
  </ToolbarFilters>
  <ToolbarActions>
    {{#if (not-eq baseKey.id '')}}
      <div class="control">
        {{#if (and capabilities.forceRevokePrefix.canUpdate (not confirmingRevoke))}}
          <ConfirmAction
            @buttonClasses="toolbar-link"
            @confirmTitle="Disable this?"
            @confirmMessage={{concat "All leases under this one will also be removed and disregard any errors encountered."}}
            @confirmButtonText="Revoke"
            @onConfirmAction={{action "revokePrefix" baseKey.id true}}
          >
            Force revoke prefix
          </ConfirmAction>
        {{/if}}
      </div>
      <div class="control">
        {{#if (and capabilities.revokePrefix.canUpdate (not confirmingForceRevoke))}}
          <ConfirmAction
            @buttonClasses="toolbar-link"
            @confirmTitle="Revoke this?"
            @confirmMessage={{concat "All leases under this one will also be removed"}}
            @confirmButtonText="Revoke"
            @onConfirmAction={{action "revokePrefix" baseKey.id}}
            data-test-lease-revoke-prefix="true"
          >
            Revoke prefix
          </ConfirmAction>
        {{/if}}
      </div>
    {{/if}}
  </ToolbarActions>
</Toolbar>

{{#if model.meta.total}}
  {{#each model as |item|}}
    {{#link-to
      (if item.isFolder "vault.cluster.access.leases.list" "vault.cluster.access.leases.show")
      item.id
      class="list-item-row"
      data-test-lease-link=item.id
    }}<Icon
      @glyph={{if item.isFolder 'folder-outline' 'file-outline'}}
      class="has-text-grey-light"
    /><span class="has-text-weight-semibold">{{or item.keyWithoutParent item.id}}</span>{{/link-to}}
  {{else}}
    <EmptyState
      @title="There are no leases matching &quot;{{this.filter}}&quot;"
    />
  {{/each}}
{{else}}
  <EmptyState
    @title={{this.emptyTitle}}
  />
{{/if}}
{{#if (gt model.meta.lastPage 1) }}
  {{list-pagination
    page=model.meta.currentPage
    lastPage=model.meta.lastPage
    link=(concat "vault.cluster.access.leases.list" (if (not baseKey.id) "-root"))
    model=(compact (array (if baseKey.id baseKey.id)))
  }}
{{/if}}
